<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Spinning Up 研究笔记 (一) - VPG  | 云玩家</title><meta name="keywords" content="机器学习,Python,强化学习,代码实例,Pytorch,Spinning Up"><meta name="author" content="云玩家"><meta name="copyright" content="云玩家"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="解决报错代码文件在 spinup&#x2F;alogs&#x2F;pytorch&#x2F;vpg&#x2F;vpg.py . 我们尝试运行代码, 然后就报错了…  12345678910...usage: ipykernel_launcher.py [-h] [--env_name ENV_NAME] [--render] [--lr LR]ipykernel_launcher.py: error: unrecognized argu">
<meta property="og:type" content="article">
<meta property="og:title" content="Spinning Up 研究笔记 (一) - VPG ">
<meta property="og:url" content="http://yunist.cn/ML/RL/spinningup/vpg/index.html">
<meta property="og:site_name" content="云玩家">
<meta property="og:description" content="解决报错代码文件在 spinup&#x2F;alogs&#x2F;pytorch&#x2F;vpg&#x2F;vpg.py . 我们尝试运行代码, 然后就报错了…  12345678910...usage: ipykernel_launcher.py [-h] [--env_name ENV_NAME] [--render] [--lr LR]ipykernel_launcher.py: error: unrecognized argu">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yunist.cn/ML/RL/spinningup/vpg/vpg.png">
<meta property="article:published_time" content="2020-07-07T15:36:58.000Z">
<meta property="article:modified_time" content="2021-08-14T04:39:34.306Z">
<meta property="article:author" content="云玩家">
<meta property="article:tag" content="机器学习">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="强化学习">
<meta property="article:tag" content="代码实例">
<meta property="article:tag" content="Pytorch">
<meta property="article:tag" content="Spinning Up">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yunist.cn/ML/RL/spinningup/vpg/vpg.png"><link rel="shortcut icon" href="/img/favicon.ico"><link rel="canonical" href="http://yunist.cn/ML/RL/spinningup/vpg/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//s4.cnzz.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script async="async" data-pjax="data-pjax" src="https://s4.cnzz.com/z_stat.php?id=1278869595&amp;web_id=1278869595"></script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script src="/js/yuntools.js"></script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-08-14 12:39:34'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/cnyist/blog/css/font.css"><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/cnyist/blog/img/avatar.svg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">40</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">27</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/chat/"><i class="fa-fw fas fa-comments"></i><span> 闲聊室</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-user"></i><span> about</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-Web"></i><span> 镜像站点</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" target="_blank" rel="noopener" href="https://yunist.gitee.io"><i class="fa-fw iconfont icon-gitee-fill-round"></i><span> Gitee Pages</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/ML/RL/spinningup/vpg/vpg.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">云玩家</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/chat/"><i class="fa-fw fas fa-comments"></i><span> 闲聊室</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-user"></i><span> about</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-Web"></i><span> 镜像站点</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" target="_blank" rel="noopener" href="https://yunist.gitee.io"><i class="fa-fw iconfont icon-gitee-fill-round"></i><span> Gitee Pages</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Spinning Up 研究笔记 (一) - VPG </h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-07-07T15:36:58.000Z" title="发表于 2020-07-07 23:36:58">2020-07-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-08-14T04:39:34.306Z" title="更新于 2021-08-14 12:39:34">2021-08-14</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">机器学习</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/%E5%BC%BA%E5%8C%96%E5%AD%A6%E4%B9%A0/">强化学习</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/%E5%BC%BA%E5%8C%96%E5%AD%A6%E4%B9%A0/Spinning-Up/">Spinning Up</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">评论数:</span><a href="/ML/RL/spinningup/vpg/#post-comment"><span id="twikoo-count"></span></a></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="解决报错"><a href="#解决报错" class="headerlink" title="解决报错"></a>解决报错</h1><p>代码文件在 <code>spinup/alogs/pytorch/vpg/vpg.py</code> . 我们尝试运行代码, 然后就报错了… </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">usage: ipykernel_launcher.py [-h] [--env_name ENV_NAME] [--render] [--lr LR]</span><br><span class="line">ipykernel_launcher.py: error: unrecognized arguments: -f xxxx.json</span><br><span class="line"></span><br><span class="line">An exception has occurred, use %tb to see the full traceback.</span><br><span class="line"></span><br><span class="line">SystemExit: <span class="number">2</span></span><br><span class="line"></span><br><span class="line">xxxx/anaconda3/lib/python3<span class="number">.7</span>/site-packages/IPython/core/interactiveshell.py:xxxx: UserWarning: To exit: use <span class="string">&#x27;exit&#x27;</span>, <span class="string">&#x27;quit&#x27;</span>, <span class="keyword">or</span> Ctrl-D.</span><br><span class="line">  warn(<span class="string">&quot;To exit: use &#x27;exit&#x27;, &#x27;quit&#x27;, or Ctrl-D.&quot;</span>, stacklevel=<span class="number">1</span>)</span><br></pre></td></tr></table></figure>

<p>嗯, 先看篇<a href="https://yunist.cn/python/another/python_error/">这篇文章</a>解决. 然后再次运行, 又报错… 这次又是啥 ?!</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">--&gt; 342     mpi_fork(args.cpu)  # run parallel code with mpi</span><br><span class="line">...</span><br><span class="line">CalledProcessError: Command <span class="string">&#x27;[&#x27;</span>mpirun<span class="string">&#x27;, &#x27;</span>-np<span class="string">&#x27;, &#x27;</span><span class="number">4</span><span class="string">&#x27;, &#x27;</span>xxxx/anaconda3/<span class="built_in">bin</span>/python<span class="string">&#x27;, &#x27;</span>xxxx/anaconda3/lib/python3<span class="number">.7</span>/site-packages/ipykernel_launcher.py<span class="string">&#x27;, &#x27;</span>-<span class="string">f&#x27;, &#x27;</span>xxxx/.local/share/jupyter/runtime/kernel-342bc725-7d2c-4cba-95f4-32c9b625dd61.json<span class="string">&#x27;]&#x27;</span> returned non-zero exit status <span class="number">1.</span></span><br></pre></td></tr></table></figure>

<p>观察了一下, 于是直接粗暴的删掉这一行 (就是这么任性) . 再次运行, 还是报错 ???</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">DependencyNotInstalled: No module named <span class="string">&#x27;mujoco_py&#x27;</span>. (HINT: you need to install mujoco_py, <span class="keyword">and</span> also perform the setup instructions here: https://github.com/openai/mujoco-py/.)</span><br></pre></td></tr></table></figure>

<p>这个问题我弄了好久, 最后发现好像是环境的问题, 我们将参数中 <code>env</code> 的值 <code>HalfCheetah-v2</code> 改为 <code>CartPole-v0</code> , 也就是</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">parser.add_argument(<span class="string">&#x27;--env&#x27;</span>, <span class="built_in">type</span>=<span class="built_in">str</span>, default=<span class="string">&#x27;HalfCheetah-v2&#x27;</span>)</span><br></pre></td></tr></table></figure>

<p>改成</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">parser.add_argument(<span class="string">&#x27;--env&#x27;</span>, <span class="built_in">type</span>=<span class="built_in">str</span>, default=<span class="string">&#x27;CartPole-v0&#x27;</span>)</span><br></pre></td></tr></table></figure>

<p>然后再次运行. 终于, 成功运行了, 这下能够愉快的开启我们的代码研究之旅了.</p>
<h1 id="Vanilla-Policy-Gradient"><a href="#Vanilla-Policy-Gradient" class="headerlink" title="Vanilla Policy Gradient"></a>Vanilla Policy Gradient</h1><p>伪代码</p>
<p><img src="1.svg"></p>
<p>使用 $\text{GAE-Lambda}$ (广义优势估计) 来进行优势估计. 因此需要拟合价值函数 $V^{\pi}(s_t)$ , 进而计算策略梯度进行优化. 有关广义优势估计的文章<a href="https://yunist.cn/ML/RL/primer/GAE/">在这</a>.</p>
<h1 id="代码详解"><a href="#代码详解" class="headerlink" title="代码详解"></a>代码详解</h1><h2 id="VPGBuffer"><a href="#VPGBuffer" class="headerlink" title="VPGBuffer"></a>VPGBuffer</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">A buffer for storing trajectories experienced by a VPG agent interacting</span></span><br><span class="line"><span class="string">with the environment, and using Generalized Advantage Estimation (GAE-Lambda)</span></span><br><span class="line"><span class="string">for calculating the advantages of state-action pairs.</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>

<p>从注释以及变量名中我们可以看出 <code>VPGBuffer</code> 是用来储存采样轨迹的各种信息的. </p>
<h2 id="store"><a href="#store" class="headerlink" title="store"></a>store</h2><p>储存轨迹中的变量, 一个很简单的函数.</p>
<h2 id="finish-path"><a href="#finish-path" class="headerlink" title="finish_path"></a>finish_path</h2><p>结束一个 epoch 时调用的函数, 用之前储存的变量来计算 <code>adv_buf</code> (广义优势) 与<code>ret_buf</code> (回报). </p>
<h3 id="self-adv-buf"><a href="#self-adv-buf" class="headerlink" title="self.adv_buf"></a>self.adv_buf</h3><p>计算广义优势估计.</p>
<p><code>last_val</code> 的作用是方便计算 <code>deltas</code> , 而 <code>deltas</code> 就是 ${\delta_1^V,\delta_2^V,\delta_3^V,\dots}$ . (见广义优势估计)</p>
<p>其中计算优势时调用了一个重要的函数 <code>core.discount_cumsum</code> 这个函数在 <code>core.poy</code> 中有定义. 注释如下</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">magic from rllab for computing discounted cumulative sums of vectors.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">input: </span></span><br><span class="line"><span class="string">    vector x, </span></span><br><span class="line"><span class="string">    [x0, </span></span><br><span class="line"><span class="string">     x1, </span></span><br><span class="line"><span class="string">     x2]</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">output:</span></span><br><span class="line"><span class="string">    [x0 + discount * x1 + discount^2 * x2,  </span></span><br><span class="line"><span class="string">     x1 + discount * x2,</span></span><br><span class="line"><span class="string">     x2]</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>

<p> 确实很 <code>magic</code> . 而由于输入是 <code>deltas</code> 与 <code>self.gamma * self.lam</code> 而由注释看出计算的其实就是广义优势估计 $ \hat{A}_t^{\mathrm{GAE}(\gamma,\lambda)}$ .</p>
<h3 id="self-ret-buf"><a href="#self-ret-buf" class="headerlink" title="self.ret_buf"></a>self.ret_buf</h3><p>计算有折损状态函数 $V^{\pi,\gamma}(s_t)$.</p>
<h2 id="VPG"><a href="#VPG" class="headerlink" title="VPG"></a>VPG</h2><p>注释中已经详细介绍了参数的意义和作用. 中间有很多保存变量, 多线程的东西, 我们都略过, 只讲算法主体部分.</p>
<h3 id="ac"><a href="#ac" class="headerlink" title="ac"></a>ac</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ac = actor_critic(env.observation_space, env.action_space, **ac_kwargs)</span><br></pre></td></tr></table></figure>

<p>由 <code>actor_critic</code> 对象生成,  <code>actor_critic</code> 是对象 <code>core.MLPActorCritic</code> , 该对象在 <code>core.py</code> 中被定义, 由其从 <code>torch.nn.Module</code> 继承可知这是个神经网络.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MLPActorCritic</span>(<span class="params">nn.Module</span>):</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, observation_space, action_space, </span></span></span><br><span class="line"><span class="function"><span class="params">                 hidden_sizes=(<span class="params"><span class="number">64</span>,<span class="number">64</span></span>), activation=nn.Tanh</span>):</span></span><br><span class="line">        <span class="built_in">super</span>().__init__()</span><br><span class="line"></span><br><span class="line">        obs_dim = observation_space.shape[<span class="number">0</span>]</span><br><span class="line"></span><br><span class="line">        <span class="comment"># policy builder depends on action space</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">isinstance</span>(action_space, Box):</span><br><span class="line">            self.pi = MLPGaussianActor(obs_dim, action_space.shape[<span class="number">0</span>], hidden_sizes, activation)</span><br><span class="line">        <span class="keyword">elif</span> <span class="built_in">isinstance</span>(action_space, Discrete):</span><br><span class="line">            self.pi = MLPCategoricalActor(obs_dim, action_space.n, hidden_sizes, activation)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># build value function</span></span><br><span class="line">        self.v  = MLPCritic(obs_dim, hidden_sizes, activation)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">step</span>(<span class="params">self, obs</span>):</span></span><br><span class="line">        <span class="keyword">with</span> torch.no_grad():</span><br><span class="line">            pi = self.pi._distribution(obs)</span><br><span class="line">            a = pi.sample()</span><br><span class="line">            logp_a = self.pi._log_prob_from_distribution(pi, a)</span><br><span class="line">            v = self.v(obs)</span><br><span class="line">        <span class="keyword">return</span> a.numpy(), v.numpy(), logp_a.numpy()</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">act</span>(<span class="params">self, obs</span>):</span></span><br><span class="line">        <span class="keyword">return</span> self.step(obs)[<span class="number">0</span>]</span><br></pre></td></tr></table></figure>

<p><code>self.pi</code> 与 <code>self.v</code> 分别是动作函数与价值函数.</p>
<p>其中出现了判断 <code>action_space</code> 是 <code>Box</code> 还是 <code>Discrete</code> 类型的代码. <code>Box</code> 与 <code>Discrete</code> 都是 <code>Space</code> 对象, 描述当前动作或环境. 其中 <code>Box</code> 表示多维连续空间, <code>Discrete</code> 表示一维离散空间. <code>MLPGaussianActor</code> 与 <code>MLPCategoricalActor</code> 都分别刻画了一个神经网络. 其输入 <code>obs_dim</code> 个数据, 输出 <code>action_space.n</code> 或者 <code>action_space.shape[0]</code> 个数据, 并且隐层由 <code>hidden_sizes</code> 指定.</p>
<p>总之, <code>ac</code> 是两个神经网络的集合, 一个是动作函数, 一个是价值函数.</p>
<h3 id="var-counts"><a href="#var-counts" class="headerlink" title="var_counts"></a>var_counts</h3><p>查看定义, 其计算的是神经网络变量的个数 (激活函数也算) .</p>
<h3 id="compute-loss-pi"><a href="#compute-loss-pi" class="headerlink" title="compute_loss_pi"></a>compute_loss_pi</h3><p>计算动作的损失, 对参数求导正是参数的梯度.</p>
<p>对参数求导后相当于用了广义优势估计 <code>adv</code> 来估计梯度.</p>
<h3 id="compute-loss-v"><a href="#compute-loss-v" class="headerlink" title="compute_loss_v"></a>compute_loss_v</h3><p>计算价值的损失, 采用了均方误差.</p>
<p>从返回值为 <code>((ac.v(obs) - ret)**2).mean()</code> 可以看出其拟合的是 <code>ret</code> 变量 (对应广义优势估计中的 $V^{\pi,\gamma}(s_t)$), 也就是状态函数 (有折损的).</p>
<h3 id="update"><a href="#update" class="headerlink" title="update"></a>update</h3><p>一个函数, 是一次 epoch 后更新参数的过程, 其中先优化策略 (<code>pi_optimizer</code>) , 然后依据 <code>train_v_tiers</code> (每次 epoch 优化价值函数参数的次数) 多次优化价值函数 (<code>vf_optimizer</code>) .</p>
<h3 id="训练过程"><a href="#训练过程" class="headerlink" title="训练过程"></a>训练过程</h3><p>先在环境中 “走” 出一个 epoch (一个 epoch 的交互数 (interaction) 由 <code>steps_per_epoch</code> 指定), 然后调用 <code>update</code>  函数优化.</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">云玩家</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://yunist.cn/ML/RL/spinningup/vpg/">http://yunist.cn/ML/RL/spinningup/vpg/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://yunist.cn" target="_blank">云玩家</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">机器学习</a><a class="post-meta__tags" href="/tags/Python/">Python</a><a class="post-meta__tags" href="/tags/%E5%BC%BA%E5%8C%96%E5%AD%A6%E4%B9%A0/">强化学习</a><a class="post-meta__tags" href="/tags/%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B/">代码实例</a><a class="post-meta__tags" href="/tags/Pytorch/">Pytorch</a><a class="post-meta__tags" href="/tags/Spinning-Up/">Spinning Up</a></div><div class="post_share"><div class="social-share" data-image="/ML/RL/spinningup/vpg/vpg.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><!-- - var pagination_cover = prev.cover === false ? prev.randomcover : prev.cover--><a href="/scribble/make_api/"><img class="prev-cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/scribble/make_api/make_api.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">零成本制作随机图片 API</div></div></a></div><!-- - var pagination_cover = next.cover == false ? next.randomcover : next.cover--><div class="next-post pull-right"><a href="/ML/RL/spinningup/begin/"><img class="next-cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/RL/spinningup/begin/begin.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Spinning Up 研究笔记 (零) - 开端</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/ML/RL/primer/Intro_to_Policy_Optimization_code/" title="Intro to Policy Optimization 代码详解"><img class="cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/RL/primer/Intro_to_Policy_Optimization_code/Intro_to_Policy_Optimization_code.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-06-25</div><div class="title">Intro to Policy Optimization 代码详解</div></div></a></div><div><a href="/ML/RL/primer/RL_demo/" title="强化学习入门 Demo"><img class="cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/RL/primer/RL_demo/RL_demo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-27</div><div class="title">强化学习入门 Demo</div></div></a></div><div><a href="/ML/RL/spinningup/begin/" title="Spinning Up 研究笔记 (零) - 开端"><img class="cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/RL/spinningup/begin/begin.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-07-07</div><div class="title">Spinning Up 研究笔记 (零) - 开端</div></div></a></div><div><a href="/ML/RL/spinningup/gym_spaces/" title="Gym 中的 gym.spaces"><img class="cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/RL/spinningup/gym_spaces/gym_spaces.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-09</div><div class="title">Gym 中的 gym.spaces</div></div></a></div><div><a href="/ML/watermelon_book/code/6/" title="《机器学习》 西瓜书实例 第 6 章: 支持向量机"><img class="cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/watermelon_book/code/6/6.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-26</div><div class="title">《机器学习》 西瓜书实例 第 6 章: 支持向量机</div></div></a></div><div><a href="/ML/watermelon_book/code/4/" title="《机器学习》 西瓜书实例 第 4 章: 决策树"><img class="cover" src="https://cdn.jsdelivr.net/gh/cnyist/blog/ML/watermelon_book/code/4/4.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-26</div><div class="title">《机器学习》 西瓜书实例 第 4 章: 决策树</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/cnyist/blog/img/avatar.svg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">云玩家</div><div class="author-info__description">云玩家's blog</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">40</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">27</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/cnyist" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/chnyist" target="_blank" title="CSDN"><i class="fas iconfont icon-CN_csdnnet"></i></a><a class="social-icon" href="https://www.zhihu.com/people/cnyist" target="_blank" title="知乎"><i class="fas iconfont icon-zhihu"></i></a><a class="social-icon" href="mailto:yunist@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3%E6%8A%A5%E9%94%99"><span class="toc-number">1.</span> <span class="toc-text">解决报错</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vanilla-Policy-Gradient"><span class="toc-number">2.</span> <span class="toc-text">Vanilla Policy Gradient</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E8%AF%A6%E8%A7%A3"><span class="toc-number">3.</span> <span class="toc-text">代码详解</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#VPGBuffer"><span class="toc-number">3.1.</span> <span class="toc-text">VPGBuffer</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#store"><span class="toc-number">3.2.</span> <span class="toc-text">store</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#finish-path"><span class="toc-number">3.3.</span> <span class="toc-text">finish_path</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#self-adv-buf"><span class="toc-number">3.3.1.</span> <span class="toc-text">self.adv_buf</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#self-ret-buf"><span class="toc-number">3.3.2.</span> <span class="toc-text">self.ret_buf</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#VPG"><span class="toc-number">3.4.</span> <span class="toc-text">VPG</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#ac"><span class="toc-number">3.4.1.</span> <span class="toc-text">ac</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#var-counts"><span class="toc-number">3.4.2.</span> <span class="toc-text">var_counts</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#compute-loss-pi"><span class="toc-number">3.4.3.</span> <span class="toc-text">compute_loss_pi</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#compute-loss-v"><span class="toc-number">3.4.4.</span> <span class="toc-text">compute_loss_v</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#update"><span class="toc-number">3.4.5.</span> <span class="toc-text">update</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%AD%E7%BB%83%E8%BF%87%E7%A8%8B"><span class="toc-number">3.4.6.</span> <span class="toc-text">训练过程</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><!-- - let post_cover = article.cover--><div class="aside-list-item"><a class="thumbnail" href="/math/set_theory/unique_ordinal/" title="序数的唯一性"><img src="https://cdn.jsdelivr.net/gh/cnyist/blog/math/set_theory/unique_ordinal/unique_ordinal.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="序数的唯一性"/></a><div class="content"><a class="title" href="/math/set_theory/unique_ordinal/" title="序数的唯一性">序数的唯一性</a><time datetime="2022-01-12T08:26:12.000Z" title="发表于 2022-01-12 16:26:12">2022-01-12</time></div></div><!-- - let post_cover = article.cover--><div class="aside-list-item"><a class="thumbnail" href="/math/mathematical_analysis/mathematical_analysis_practice/3/3-1/" title="(史济怀) 数学分析教程上册第 3 版-练习题 3.1"><img src="https://cdn.jsdelivr.net/gh/cnyist/blog/math/mathematical_analysis/mathematical_analysis_practice/3/3-1/math.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="(史济怀) 数学分析教程上册第 3 版-练习题 3.1"/></a><div class="content"><a class="title" href="/math/mathematical_analysis/mathematical_analysis_practice/3/3-1/" title="(史济怀) 数学分析教程上册第 3 版-练习题 3.1">(史济怀) 数学分析教程上册第 3 版-练习题 3.1</a><time datetime="2021-10-19T00:30:55.000Z" title="发表于 2021-10-19 08:30:55">2021-10-19</time></div></div><!-- - let post_cover = article.cover--><div class="aside-list-item"><a class="thumbnail" href="/math/mathematical_analysis/mathematical_analysis_practice/2/2-11/" title="(史济怀) 数学分析教程上册第 3 版-练习题 2.11"><img src="https://cdn.jsdelivr.net/gh/cnyist/blog/math/mathematical_analysis/mathematical_analysis_practice/2/2-11/2-11.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="(史济怀) 数学分析教程上册第 3 版-练习题 2.11"/></a><div class="content"><a class="title" href="/math/mathematical_analysis/mathematical_analysis_practice/2/2-11/" title="(史济怀) 数学分析教程上册第 3 版-练习题 2.11">(史济怀) 数学分析教程上册第 3 版-练习题 2.11</a><time datetime="2021-09-25T03:37:28.000Z" title="发表于 2021-09-25 11:37:28">2021-09-25</time></div></div><!-- - let post_cover = article.cover--><div class="aside-list-item"><a class="thumbnail" href="/math/mathematical_analysis/mathematical_analysis_practice/2/2-10/" title="(史济怀) 数学分析教程上册第 3 版-练习题 2.10"><img src="https://cdn.jsdelivr.net/gh/cnyist/blog/math/mathematical_analysis/mathematical_analysis_practice/2/2-10/2-10.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="(史济怀) 数学分析教程上册第 3 版-练习题 2.10"/></a><div class="content"><a class="title" href="/math/mathematical_analysis/mathematical_analysis_practice/2/2-10/" title="(史济怀) 数学分析教程上册第 3 版-练习题 2.10">(史济怀) 数学分析教程上册第 3 版-练习题 2.10</a><time datetime="2021-09-22T07:36:49.000Z" title="发表于 2021-09-22 15:36:49">2021-09-22</time></div></div><!-- - let post_cover = article.cover--><div class="aside-list-item"><a class="thumbnail" href="/math/mathematical_analysis/mathematical_analysis_practice/2/2-9/" title="(史济怀) 数学分析教程上册第 3 版-练习题 2.9"><img src="https://cdn.jsdelivr.net/gh/cnyist/blog/math/mathematical_analysis/mathematical_analysis_practice/2/2-9/2-9.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="(史济怀) 数学分析教程上册第 3 版-练习题 2.9"/></a><div class="content"><a class="title" href="/math/mathematical_analysis/mathematical_analysis_practice/2/2-9/" title="(史济怀) 数学分析教程上册第 3 版-练习题 2.9">(史济怀) 数学分析教程上册第 3 版-练习题 2.9</a><time datetime="2021-09-20T08:19:06.000Z" title="发表于 2021-09-20 16:19:06">2021-09-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 云玩家</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer><script>document.getElementById('web_bg').style = 'background-image: url("' + get_rand_jsd_pic('cnyist', 'banner@master', '/', 70, '-min.jpg') + '")'</script></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    loader: {
      source: {
        '[tex]/amsCd': '[tex]/amscd'
      }
    },
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        addClass: [200,() => {
          document.querySelectorAll('mjx-container:not([display=\'true\']').forEach( node => {
            const target = node.parentNode
            if (!target.classList.contains('has-jax')) {
              target.classList.add('mathjax-overflow')
            }
          })
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>(()=>{
  const $countDom = document.getElementById('twikoo-count')
  const init = () => {
    let initData = {
      el: '#twikoo-wrap',
      envId: 'yunist-147dfe',
      region: ''
    }

    if (false) {
      const otherData = false
      initData = Object.assign(initData, otherData)
    }
    
    twikoo.init(initData)
  }

  const getCount = () => {
    twikoo.getCommentsCount({
      envId: 'yunist-147dfe',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      $countDom.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const loadTwikoo = (bool = false) => {
    if (typeof twikoo === 'object') {
      init()
      bool && $countDom && setTimeout(getCount,0)
    } else {
      getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js').then(()=> {
        init()
        bool && $countDom && setTimeout(getCount,0)
      })
    }
  }

  if ('Twikoo' === 'Twikoo' || !false) {
    if (false) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo(true)
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>